<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Page</title>

</head>
<style>
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.login-container {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    width: 300px;
    text-align: center;
}

.login-container h2 {
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
}

.form-group input {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
}

button {
    width: 100%;
    padding: 10px;
    background-color: #007bff;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

button:hover {
    background-color: #0056b3;
}

a {
    color: #007bff;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}
</style>
<body>
    <div class="login-container">
        <h2>登录</h2>
        
            <div class="form-group">
                <label for="username">Username</label>
                <input type="text" id="username" name="username" required>
            </div>
            <div class="form-group">
                <label for="password">Password</label>
                <input type="password" id="password" name="password" required>
            </div>
            <button>登录</button>
  
       
    </div>
</body>
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
<script>

$('button').click(function() {
    $.ajax({
        type: 'post',
        url: 'http://localhost:3000/users/login',  // 确保路径正确
        data: {
            user: $('#username').val(),
            password: $('#password').val(),
        },
        dataType: 'json',
        success: function(data) {
            console.log(data);
            
            if (data.code == 200) {
                localStorage.setItem("token", data.token);
                localStorage.setItem("user",$('#username').val());
                alert('登录成功');
                location.assign('./相册.html');
            } else {
                alert('登录失败');
            }
        },
        error: function(err) {
            console.log(err);
        }
    });
});

</script>
</html>